from util.excel_comm import Oper_Excel
import configData.config_data
from util.json_comm import Oper_Json

class GetData():
    def __init__(self):
        self.excel_op = Oper_Excel()
        self.data = configData.config_data

    # 获取excel行数，就是我们的case行数
    def get_case_lines(self):
        return self.excel_op.get_lines()

    def get_is_run(self, row):  # 传入行
        col = self.data.get_run()
        run_model = self.excel_op.get_cell_value(row, col)
        print(run_model)
        if run_model == "yes":
            flag = True
        else:
            flag = False
        return flag

    def is_header(self, row):  # 是否需要header
        col = self.data.get_header()
        header = self.excel_op.get_cell_value(row, col)
        if header == 'yes':
            resule = self.data.get_hearder_value()
        else:
            resule = None
        return resule

    def get_request_method(self,row):#获取request方法，post or get
        col = self.data.get_run_way()
        request_method = self.excel_op.get_cell_value(row,col)
        return request_method

    def get_request_url(self,row):#获取行号
        col = self.data.get_url()
        url = self.excel_op.get_cell_value(row,col)
        return url

    def get_request_data(self,row):#请求数据
        col = self.data.get_request_data()
        req_data = self.excel_op.get_cell_value(row,col)
        if req_data=="":
            return None
        else:
            return req_data


    #通过关键字拿到data数据
    def get_data_for_json(self,row):
        json_data = Oper_Json()
        request_data = json_data.get_data(self.get_request_data(row))


    def get_expect_data(self,row):
        col=self.data.get_expect()
        expect = self.excel_op.get_cell_value(row,col)
        if expect=='':
            return None
        return expect